package com.progark.sound.model;

import java.util.ArrayList;

import com.progark.sound.main.Constants;

import sheep.audio.Sound;
import sheep.graphics.Image;

public class Task {
	
	private Sound sound;
	private Alternative alternative1, alternative2, alternative3, alternative4;
	private Image hint;
	
	public Task(String soundPath, String hint, String alt1, String alt2, String alt3, String alt4){
		sound = new Sound(Constants.SOUNDMAP.get(soundPath));
		createAlternatives(alt1,alt2,alt3,alt4);
		this.hint = new Image(Constants.HINTMAP.get(hint));
	}
	
	private void createAlternatives(String alt1, String alt2, String alt3, String alt4){
		ArrayList<String> tempList = new ArrayList<String>();
		tempList.add(alt1);
		tempList.add(alt2);
		tempList.add(alt3);
		tempList.add(alt4);
		ArrayList<String> randlist = new ArrayList<String>();
		while(!tempList.isEmpty()){
			int i = (int) Math.floor(Math.random()*tempList.size());
			randlist.add(tempList.get(i));
			tempList.remove(i);
		}
		alt1 = randlist.get(0);
		alt2 = randlist.get(1);
		alt3 = randlist.get(2);
		alt4 = randlist.get(3);
		
		if (alt1.contains("*"))
			alternative1 = new Alternative(alt1.replace("*", ""), true);
		else
			alternative1 = new Alternative(alt1, false);
		if (alt2.contains("*"))
			alternative2 = new Alternative(alt2.replace("*", ""), true);
		else
			alternative2 = new Alternative(alt2, false);
		if (alt3.contains("*"))
			alternative3 = new Alternative(alt3.replace("*", ""), true);
		else
			alternative3 = new Alternative(alt3, false);
		if (alt4.contains("*"))
			alternative4 = new Alternative(alt4.replace("*", ""), true);
		else
			alternative4 = new Alternative(alt4, false);
	}

	public Sound getSound() {
		return sound;
	}

	public Alternative getAlternative1() {
		return alternative1;
	}

	public Alternative getAlternative2() {
		return alternative2;
	}

	public Alternative getAlternative3() {
		return alternative3;
	}

	public Alternative getAlternative4() {
		return alternative4;
	}
	
	public ArrayList<Alternative> getAltList(){
		ArrayList<Alternative> templist = new ArrayList<Alternative>();
		templist.add(alternative1);
		templist.add(alternative2);
		templist.add(alternative3);
		templist.add(alternative4);
		return templist;
	}

	public Image getHint() {
		return hint;
	}
	

}
